SC_BEGIN_PACKAGE(DOC)

OPTION(SC_DOC_GENERATE "Generate documentation" OFF)

IF (SC_DOC_GENERATE)
	OPTION(SC_DOC_GENERATE_HTML "Generate HTML documentation" ON)
	OPTION(SC_DOC_GENERATE_MAN "Generate MAN pages" ON)
	OPTION(SC_DOC_GENERATE_PDF "Generate PDF manual" OFF)

	SET(DOC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})

	IF(SC_ENABLE_CONTRIB)
		LIST(APPEND OPTS "--all")
	ENDIF()

	IF (SC_DOC_GENERATE_HTML)
		LIST(APPEND OPTS "--html")
	ENDIF()

	IF (SC_DOC_GENERATE_MAN)
		LIST(APPEND OPTS "--man")
	ENDIF()

	IF (SC_DOC_GENERATE_PDF)
		LIST(APPEND OPTS "--pdf")
	ENDIF()

	ADD_CUSTOM_TARGET(
		scdoc ALL
		COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/build-doc.py ${OPTS} ${DOC_BUILD_DIR}
		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	)

	IF (SC_DOC_GENERATE_HTML)
		INSTALL(DIRECTORY ${DOC_BUILD_DIR}/html DESTINATION ${SC3_PACKAGE_SHARE_DIR}/doc/seiscomp)
	ENDIF()

	IF (SC_DOC_GENERATE_MAN)
		INSTALL(DIRECTORY ${DOC_BUILD_DIR}/man1 DESTINATION ${SC3_PACKAGE_SHARE_DIR}/man)
	ENDIF()

	IF (SC_DOC_GENERATE_PDF)
		INSTALL(FILES ${DOC_BUILD_DIR}/pdf/latex/SeisComP.pdf DESTINATION ${SC3_PACKAGE_SHARE_DIR}/doc/seiscomp)
	ENDIF()
ENDIF (SC_DOC_GENERATE)
